package com.summer.campussct.controller;


import com.summer.campussct.annotation.Permission;
import com.summer.campussct.pojo.dto.*;
import com.summer.campussct.service.IVehicleService;
import com.summer.campussct.utils.UserIdHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mr.Chen
 * @since 2024-04-21
 */
@RestController
@RequestMapping("/vehicle")
@Api(tags = "车辆相关API")
public class VehicleController {

    @Resource
    private IVehicleService vehicleService;

    @ApiOperation("添加车辆")
    @PostMapping("add2")
    @Permission
    public RestResult addVehicle2(@RequestBody @Validated VehicleInfoDto vehicleInfoDto){
        long userId = UserIdHolder.getId();
        vehicleInfoDto.getVehicleMarket().setUid(userId);
        return vehicleService.addVehicle2(vehicleInfoDto);
    }

    @ApiOperation("修改车辆")
    @PutMapping("modify")
    @Permission
    public RestResult modifyVehicle(@RequestBody @Validated VehicleInfoDto vehicleInfoDto){
        return vehicleService.modifyVehicle(vehicleInfoDto);
    }

    @ApiOperation("删除车辆")
    @DeleteMapping("delete/{id}")
    @Permission
    public RestResult deleteVehicle(@PathVariable("id") long id){
        return vehicleService.deleteVehicle(id);
    }

    @ApiOperation("publish页：获取用户发布的车辆")
    @GetMapping("publishes")
    @Permission
    public RestResult publishes(PublishQueryParams publishQueryParams){
        long userId = UserIdHolder.getId();
        publishQueryParams.setUserId(userId);
        return vehicleService.getVehicleByUser(publishQueryParams);
    }

    @ApiOperation("审批页：查询未审批的车辆")
    @GetMapping("auditList")
    public RestResult getAuditList(){
        return vehicleService.getAuditList();
    }

    @ApiOperation("预览车辆：审批页和预览页(未发布)")
    @GetMapping("browse/{id}")
    public RestResult browse(@PathVariable("id") long id){
        return vehicleService.browseVehicle(id);
    }
}

